#ifndef __INVOKE_GUEST__
#define __INVOKE_GUEST__

#include "mink.h"

typedef struct _UNICODE_STRING32 {
	USHORT Length;
	USHORT MaximumLength;
	UINT32 Buffer;
} UNICODE_STRING32;

typedef struct _UNICODE_STRING64 {
	USHORT Length;
	USHORT MaximumLength;
	UINT64 Buffer;
} UNICODE_STRING64;

typedef UINT64	GCPTR64;

GCPTR64 FillUnicodeString( IProcess * proc, GCPTR64 puc, LPCWSTR wName )
{
	SIZE_T chName = wcslen(wName) + 1;
	SIZE_T cbAlloc = chName * sizeof(wchar_t);
	GCPTR64 guestString = McAllocateHeap( McGetProcessHeap(), 0, cbAlloc );
	if( !guestString ) return NULL;
	UNICODE_STRING32 tmp;
	tmp.Length = chName - 1;
	tmp.MaximumLength = tmp.Length;
	tmp.Buffer = guestString;
	proc->vmwrite( puc, &tmp, sizeof(tmp) );
	proc->vmwrite( tmp.Buffer, wName, chName * sizeof(wchar_t) );
	return guestString;
}

GCPTR64 AllocUnicodeString( IProcess * proc, LPCWSTR wName )
{
	SIZE_T chName = wcslen(wName) + 1;
	SIZE_T cbAlloc = chName * sizeof(wchar_t) + sizeof(UNICODE_STRING);
	UINT64 Addr = McAllocateHeap( McGetProcessHeap(), 0, cbAlloc );
	if( !Addr ) return NULL;
	UNICODE_STRING32 tmp;
	tmp.Length = chName - 1;
	tmp.MaximumLength = tmp.Length;
	tmp.Buffer = Addr + sizeof(UNICODE_STRING);
	proc->vmwrite( Addr, &tmp, sizeof(tmp) );
	proc->vmwrite( tmp.Buffer, wName, chName * sizeof(wchar_t) );
	return Addr;
}



#endif